<?php
class model_user extends CI_Model {

	public function __construct()
	{
	//ini_set('memory_limit', '-1');
		$this->load->library('fclass');
		$this->load->database();
	}
	

	public function select($data)
	{		
		$this->db->select('*');
		$this->db->from('tblusers');
		
		if(count($data["array_uId"])>1)
			$this->db->or_where_in('uId', $data["array_uId"]); 

		if(isset($data["where"])&&$data["where"]!="")
			$this->db->like('uFullname', $data["where"]); 

		if(isset($data["order_by"])&&$data["order_by"]!="")
			$this->db->order_by($data["order_by"]); 
		
		if(isset($data["limit"])&&$data["limit"]!="")
			$this->db->limit($data["limit"], $data["paging"]);

		$query = $this->db->get();
		return $query->result_array();		
	}

	public function selectParent($data)
	{		
		$this->db->select('*');
		$this->db->from('tblusers');
		if(isset($data["rId"]))
			$this->db->like('rId', $data["rId"],'after'); 

		$this->db->where("rId",'1.1.1.5');
		$this->db->where("uStatus",$data["uStatus"]);

		if(isset($data["where"])&&$data["where"]!="")
			$this->db->like('uFullname', $data["where"]); 

		if(isset($data["order_by"])&&$data["order_by"]!="")
			$this->db->order_by($data["order_by"]); 
		
		if(isset($data["limit"])&&$data["limit"]!="")
			$this->db->limit($data["limit"], $data["paging"]);


		$query = $this->db->get();
		return $query->result_array();		
	}


	public function selectParentCount($data)
	{		
		$this->db->select('*');
		$this->db->from('tblusers');
		if(isset($data["rId"]))
			$this->db->like('rId', $data["rId"],'after'); 

		$this->db->where("rId",'1.1.1.5');
		$this->db->where("uStatus",$data["uStatus"]);

		if(isset($data["where"])&&$data["where"]!="")
			$this->db->like('uFullname', $data["where"]); 

		$query = $this->db->get();
		return $query->num_rows();		
	}

	public function selectDetailId($data)
	{		
		$this->db->select('*');
		$this->db->from('tblusers');
		$this->db->where("uId",$data["uId"]);
		$query = $this->db->get();
		return $query->row_array();		
	}

	public function selectSaleConflict($data)
	{		

		$this->db->select('*');
		$this->db->from('tblusers');
		$this->db->join('tbl_customers', 'tbl_customers.cust_creator_id = tblusers.uId');
		$this->db->where("cust_conflict_id",$data["cust_conflict_id"]);
		$this->db->or_where("tbl_customers.cust_id",$data["cust_id"]);

		
		/*
		$this->db->select('*');
		$this->db->from('tblusers');
		$this->db->join('tbl_customers', 'tbl_customers.cust_creator_id = tblusers.uId');
		$this->db->where("(
			  				(
			  					cust_conflict_id='".$this->fclass->cleanup_text($data["cust_conflict_id"])."' 
								AND cust_creator_id!='".$this->fclass->cleanup_text($data["cust_id"])."'
							) OR  tbl_customers.cust_id ='".$this->fclass->cleanup_text($data["cust_id"])."'
						) 	AND ( tblusers.uId!='".$this->fclass->cleanup_text($data["uId"])."' OR tblusers.uUserType ='1' )");
		//$this->db->where("(tblusers.uId='".$this->fclass->cleanup_text($data["uId"])."' OR  tblusers.uUserType ='1') ");
		*/
		$query = $this->db->get();
		return $query->result_array();		
	}

	public function selectPermitionApp($data){
		$this->db->select('*');
		$this->db->from('tbl_app_permissions');
		$this->db->where("user_id",$data["user_id"]);
		$this->db->where("app_id",$data["app_id"]);
		$query = $this->db->get();
		return $query->row_array();	
	}
	
}
	
?>